<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String baseBath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>营销机会管理</title>
    <base href=<%=baseBath%>
    <%@include file="../common_css.jsp"%>
</head>
<body class="childrenBody">

<form class="layui-form" >
    <blockquote class="layui-elem-quote quoteBox">

        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="customerName"
                           class="layui-input
							searchVal" placeholder="客户名" />
                </div>
                <div class="layui-input-inline">
                    <select name="userId"  id="userId">
                        <option value="-1" >全部员工</option>

                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="state"  id="state">
                        <option value="-1" >全部线索状态</option>

                    </select>
                </div>
                <a class="layui-btn search_btn" data-type="reload"><i
                        class="layui-icon">&#xe615;</i> 搜索</a>
            </div>
        </form>

    </blockquote>
    <table id="saleChanceList" class="layui-table"  lay-filter="saleChances"></table>



    <script type="text/html" id="toolbarDemo">

        <div class="layui-btn-container">

            <a class="layui-btn layui-btn-normal addNews_btn" lay-event="add">
                <i class="layui-icon">&#xe608;</i>
                添加
            </a>

            <a class="layui-btn layui-btn-normal delNews_btn" lay-event="del">
                <i class="layui-icon">&#xe608;</i>
                删除
            </a>

        </div>

    </script>

    <!--操作-->
    <script id="saleChanceListBar" type="text/html">
        <a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">编辑</a>
        {{# if (d.intentionState=='1') { }}
        <a href="javascript:;"  class="layui-btn layui-btn-warm layui-btn-xs"  lay-event="dev">开发</a>
        {{# } else { }}
        <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs"  lay-event="info">详情</a>
        {{# } }}
    </script>

</form>
<script type="text/javascript">
    layui.use(['table','layer'],function(){
        var layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            table = layui.table;
        //营销机会列表展示
        var  tableIns = table.render({
            elem: '#saleChanceList',
            url : 'cusIntention/list',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limits : [10,15,20,25],
            limit : 10,
            toolbar: "#toolbarDemo",
            id : "saleChanceListTable",
            method : 'post',
            cols : [[
                {type: "checkbox", fixed:"center"},
                {field: "id", title:'编号',fixed:"true"},
                {field:'title', title: '客户姓名',templet: function(d){
                        return d.customer.name
                    }},
                {field:'phone', title: '手机号',templet: function(d){
                        return d.customer.phone
                    }},
                {field: 'describe', title: '客户描述',align:"center"},
                {field: 'stringDriveInterest', title: '试驾兴趣',align:"center"},
                {field: 'stringIntentionState', title: '线索状态',  align:'center'},
                {field: 'userName', title: '接待员工', align:'center',templet:function (d){
                        return d.customer.user.name
                    }},
                {title: '操作', templet:'#saleChanceListBar',fixed:"right",align:"center", minWidth:150},
                {title: 'cus_id',hide: true ,templet:function (d){
                        return d.customer.id
                    }}
            ]]
        });

        table.on('tool(saleChances)',function (obj) {
            var layEvent =obj.event;
            if(layEvent === "edit"){
                openAddOrUpdateSaleChanceDialog(obj.data.id);
            }else if(layEvent === "del"){
                layer.confirm("确认删除当前记录?",{icon: 3, title: "机会数据管理"},function (index) {
                    $.post(ctx+"/sale_chance/delete",{ids:obj.data.id},function (data) {
                        if(data.code==200){
                            layer.msg("删除成功");
                            tableIns.reload();
                        }else{
                            layer.msg(data.msg);
                        }
                    })
                })
            }else if(layEvent==="dev"||layEvent==="info"){
                layui.layer.open({
                    title:'计划项数据详情',
                    type:2,
                    area:["800px","550px"],
                    maxmin:true,
                    content:"cusDevelop/toCusDevData?id="+$(this).parent().parent().next().children().text()
                })
            }
        });

        /**
         * 打开添加或更新对话框
         */
        function openAddOrUpdateSaleChanceDialog(id) {
            var title="营销机会管理-机会添加";
            var url = "cusIntention/toIntentionInsertAndUpdate";
            if(id){
                title="营销机会管理-机会更新";
                url = url+"?id="+id;
            }
            layui.layer.open({
                title:title,
                type:2,
                area:["700px","500px"],
                maxmin:true,
                content:url
            })
        }

        $.post("user/findUser",function (res) {
            for(var i=0;i<res.length;i++){
                //绑定下拉框显示
                $("#userId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>");
            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        $.post("dictionaries/findIntentionState",function (res) {
            for(var i=0;i<res.length;i++) {
                $("#state").append("<option value=\"" + res[i].valueId + "\"   >" + res[i].valueName + "</option>");
            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        // 多条件搜索
        $(".search_btn").on("click",function () {
            table.reload("saleChanceListTable",{
                page:{
                    curr:1
                },
                where:{
                    customerName:$("input[name='customerName']").val(),// 客户名
                    userId:$("#userId").val(),// 客户名
                    state:$("#state").val()    //分配状态
                },
                url:'cusIntention/condition',
                contentType:"application/json"
            })
        });


        // 头工具栏事件
        table.on('toolbar(saleChances)',function (obj) {
            switch (obj.event) {
                case "add":
                    openAddOrUpdateSaleChanceDialog();
                    break;
                // case "del":
                //     delSaleChance(table.checkStatus(obj.config.id).data);
                //     break;
            }
        });


        // function delSaleChance(datas){
        //     /**
        //      * 批量删除
        //      *   datas:选择的待删除记录数组
        //      */
        //     if(datas.length==0){
        //         layer.msg("请选择待删除记录!");
        //         return;
        //     }
        //
        //     layer.confirm("确定删除选中的记录",{
        //         btn:['确定','取消']
        //     },function (index) {
        //         layer.close(index);
        //         // ids=10&ids=20&ids=30
        //         var ids="ids=";
        //         for(var i=0;i<datas.length;i++){
        //             if(i<datas.length-1){
        //                 ids=ids+datas[i].id+"&ids=";
        //             }else{
        //                 ids=ids+datas[i].id;
        //             }
        //         }
        //
        //         $.ajax({
        //             type:"post",
        //             url:ctx+"/sale_chance/delete",
        //             data:ids,
        //             dataType:"json",
        //             success:function (data) {
        //                 if(data.code==200){
        //                     tableIns.reload();
        //                 }else{
        //                     layer.msg(data.msg);
        //                 }
        //             }
        //         })
        //     })
        // }
    });

</script>
</body>
</html>